/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

var fieldLabel = new Array("序号","测点名称","电压等级(kV)","最高","最低","不合格时间(分)","不可调整","调整不良","不可调整","调整不良","总供电时间(分)","本月","季度","年累","原因分析","处理措施","完成情况","备注");
           
var fieldName=new Array("id","cdmc","dydj","zg","zd","bktz","tzbl","bktz","tzbl","zgdsj","by","jd","nl","yyfx","clcs","wcqk","bz");
var record_start = 0;
var _pageSize = 20;
var store;
var theme = '告警';
var now = new Date();
var beginDate = now.format('Y-m');
var endDate=now.add(Date.MONTH,-1).format('Y-m');


var pointTypeStore = new Ext.data.JsonStore({
    url: '../../servlet/common/SimpleInfoLoad',
    baseParams: {
        id: 'id', 
        name: 'name', 
        tableName: 't_pointType'
    },
    autoLoad: true,
    root: 'data',
    fields: ['id', 'name']
});

var pointTypeCombo = {
    xtype: 'combo',
    store: pointTypeStore,
    id: 'PointTypeCombo',
    displayField: 'name',
    valueField: 'id',
    hiddenName: 'pointTypeId',    
    mode: 'remote', 
    forceSelection: true,
    allowBlank: false,
    blankText: '不允许为空',
    triggerAction: 'all',
    fieldLabel: '监测点类型',
    emptyText: '请选择监测点类型...',
    selectOnFocus: true
}        

var pointTypeStore = new Ext.data.JsonStore({
    url: '../../servlet/common/SimpleInfoLoad',
    baseParams: {id: 'id', name: 'name', tableName: 't_pointType2'},
    autoLoad: true,
    root: 'data',
    fields: ['id', 'name']
});

var pointTypeCombo2 = {
    xtype: 'combo',
    store: pointTypeStore,
    id: 'PointTypeCombo2',
    displayField: 'name',
    valueField: 'id',
    hiddenName: 'pointType2Id',    
    mode: 'remote', 
    forceSelection: true,
    allowBlank: false,
    blankText: '不允许为空',
    triggerAction: 'all',
    fieldLabel: '城农网类别',
    emptyText: '请选择城农网类别...',
    selectOnFocus: true
}

var dateFrom = {
    xtype: 'datefield',
    id: 'DateFrom',
    format: 'Y年m月',
    width: 150,
    value:now.add(Date.MONTH,-1),
    listeners: {
        select: function(c, date) {
            beginDate = date.format('Y-m');
            store.baseParams.beginDate = beginDate;
        }
    }  
}

var dateTo={
    xtype: 'datefield',
    id: 'DateTo',
    format: 'Y年m月',
    width: 150,
    value:now,
    listeners: {
        select: function(c, date) {
            beginDate = date.format('Y-m');
            store.baseParams.beginDate = beginDate;
        }
    }
}

function downloadExcel(){
    var datefrom=DateFrom.value;
    var dateto=DateTo.value;
    var PointType = PointTypeCombo.value;
    var PointType2 = PointTypeCombo2.value;
    params={
        PointType:PointType,
        PointType2:PointType2,
        datefrom:datefrom,
        dateto:dateto
    };
    var encodeParams = Ext.urlEncode(params);
    open('../../servlet/ExcelFileCreate?'+encodeParams);
}
/*Ext.onReady(function() {
                    new Ext.Viewport({
                            layout: 'fit',
                            items: [{
                                    xtype: 'grid',
                                    title: '供电电压逐点统计表',
                                    store: new Ext.data.JsonStore({
                                            fields: [fieldName[0], fieldName[1], fieldName[2], fieldName[3], fieldName[4], fieldName[5], fieldName[6],fieldName[7], fieldName[8],
                                                fieldName[9], fieldName[10], fieldName[11], fieldName[12], fieldName[13], fieldName[14], fieldName[15],fieldName[16]],
                                            url:"../../servlet/report/points",
                                             autoLoad: true,
                                            root: 'data'
                                    }),
                                    colModel: new Ext.grid.ColumnModel({
                                            columns: [
                                                new Ext.grid.RowNumberer({header : fieldLabel[0],align: 'center', width : 40,renderer: function (value, metadata, record, rowIndex) {return record_start + 1 + rowIndex;} }),
                                                    {header: fieldLabel[1], width: 50, dataIndex: fieldName[1], align: 'center'},
                                                    {header: fieldLabel[2], width: 50, dataIndex: fieldName[2], align: 'center'},
                                                    {header: fieldLabel[3], width: 50, dataIndex: fieldName[3], align: 'center'},
                                                    {header: fieldLabel[4], width: 50, dataIndex: fieldName[4], align: 'center'},
                                                    {header: fieldLabel[5], width: 80, dataIndex: fieldName[5], align: 'center'},
                                                    {header: '越上限时间(分)', width: 50, dataIndex: fieldName[6], align: 'center'},
                                                    //{header: fieldLabel[7], width: 50, dataIndex: fieldName[7], align: 'center'},
                                                    {header: '越下限时间(分)', width: 80, dataIndex: fieldName[8], align: 'center'},
                                                    //{header: fieldLabel[9], width: 50, dataIndex: fieldName[9], align: 'center'},
                                                    {header: fieldLabel[10], width: 50, dataIndex: fieldName[10], align: 'center'},
                                                    {header: fieldLabel[11], width: 50, dataIndex: fieldName[11], align: 'center'},
                                                    {header: fieldLabel[12], width: 50, dataIndex: fieldName[12], align: 'center'},
                                                    {header: fieldLabel[13], width: 50, dataIndex: fieldName[13], align: 'center'},
                                                    //{header: fieldLabel[14], width: 50, dataIndex: fieldName[14], align: 'center'},
                                                    //{header: fieldLabel[15], width: 50, dataIndex: fieldName[15], align: 'center'},
                                                    //{header: fieldLabel[16], width: 50, dataIndex: fieldName[16], align: 'center'},
                                            ],
                                            
                                            defaultSortable: true,
                                            rows: [
                                                    [
                                                            {rowspan: 1},
                                                            {rowspan: 1},
                                                            {rowspan: 1},
                                                            {header: '电压变化范围(kV)', colspan: 2, align: 'center'}, 
                                                            {rowspan: 1},
                                                            //{header: '越上限时间(分)', colspan: 2, align: 'center'},
                                                            //{header: '越下限时间(分)', colspan: 2, align: 'center'},
                                                            
                                                            {rowspan: 1},
                                                            {rowspan: 1},
                                                            {rowspan: 1},
                                                            {header:'合格率(%)', colspan: 3, align: 'center'},
                                                            //{rowspan: 1},
                                                            //{rowspan: 1},
                                                            //{rowspan: 1},
                                                    ], 
                                            ]
                                    }),
                                    enableColumnMove: false,
                                    viewConfig: {
                                            forceFit: true
                                    },
                                    plugins: [new Ext.ux.plugins.GroupHeaderGrid()]
                            }]
                    });
            });*/
function buildWindow(){
    store=new Ext.data.JsonStore({               
        url:"../../servlet/report/points",
        root: 'data',
        idProperty: 'id',
        totalProperty: 'count',
        fields: fieldName,
        autoLoad: true
    });
    colModel= new Ext.grid.ColumnModel({
        columns: [
        new Ext.grid.RowNumberer({
            header : fieldLabel[0],
            align: 'center', 
            width : 40,
            renderer: function (value, metadata, record, rowIndex) {
                return record_start + 1 + rowIndex;
            }
        }),

        {
            header: fieldLabel[1], 
            width: 100, 
            dataIndex: fieldName[1], 
            align: 'center'
        },

        {
            header: fieldLabel[2], 
            width: 100, 
            dataIndex: fieldName[2], 
            align: 'center'
        },

        {
            header: fieldLabel[3], 
            width: 100, 
            dataIndex: fieldName[3], 
            align: 'center'
        },

        {
            header: fieldLabel[4], 
            width: 100, 
            dataIndex: fieldName[4], 
            align: 'center'
        },

        {
            header: fieldLabel[5], 
            width: 80, 
            dataIndex: fieldName[5], 
            align: 'center'
        },

        {
            header: '越上限时间(分)', 
            width: 100, 
            dataIndex: fieldName[6], 
            align: 'center'
        },

        //{header: fieldLabel[7], width: 100, dataIndex: fieldName[7], align: 'center'},

        {
            header: '越下限时间(分)', 
            width: 80, 
            dataIndex: fieldName[8], 
            align: 'center'
        },

        //{header: fieldLabel[9], width: 100, dataIndex: fieldName[9], align: 'center'},

        {
            header: fieldLabel[10], 
            width: 100, 
            dataIndex: fieldName[10], 
            align: 'center'
        },

        {
            header: fieldLabel[11], 
            width: 100, 
            dataIndex: fieldName[11], 
            align: 'center'
        },

        {
            header: fieldLabel[12], 
            width: 100, 
            dataIndex: fieldName[12], 
            align: 'center'
        },

        {
            header: fieldLabel[13], 
            width: 100, 
            dataIndex: fieldName[13], 
            align: 'center'
        },
        //{header: fieldLabel[14], width: 50, dataIndex: fieldName[14], align: 'center'},
        //{header: fieldLabel[15], width: 50, dataIndex: fieldName[15], align: 'center'},
        //{header: fieldLabel[16], width: 50, dataIndex: fieldName[16], align: 'center'},
        ],

        defaultSortable: true,
        rows: [
        [
        {
            width: 100, 
            rowspan: 1
        },

        {
            width: 100, 
            rowspan: 1
        },

        {
            width: 100, 
            rowspan: 1
        },

        {
            width: 100, 
            header: '电压变化范围(kV)', 
            colspan: 2, 
            align: 'center'
        }, 

        {
            width: 100, 
            rowspan: 1
        },

        //{header: '越上限时间(分)', colspan: 2, align: 'center'},

        //{header: '越下限时间(分)', colspan: 2, align: 'center'},


        {
            width: 100, 
            rowspan: 1
        },

        {
            width: 100, 
            rowspan: 1
        },

        {
            width: 100, 
            rowspan: 1
        },

        {
            width: 100, 
            header:'合格率(%)', 
            colspan: 3, 
            align: 'center'
        },
        //{rowspan: 1},
        //{rowspan: 1},
        //{rowspan: 1},
        ], 
        ]
    });
                                    
    var grid = new Ext.grid.GridPanel({
        title: '供电电压逐点统计表',
        store: store,
        colModel:colModel,
        enableColumnMove: false,
        viewConfig: {
            forceFit: false
        },
        plugins: [new Ext.ux.plugins.GroupHeaderGrid()],
        loadMask: true,
        tbar: new Ext.Toolbar([
        {
            text: "选择开始日期：", 
            xtype: 'label', 
            style: {
                marginLeft: '20px'
            }
        },
        dateFrom,
        '-',
        {
            text: "选择结束日期：", 
            xtype: 'label', 
            style: {
                marginLeft: '20px'
            }
        },
        dateTo,
        '-',
        {
            text: "监测点类型：", 
            xtype: 'label', 
            style: {
                marginLeft: '20px'
            }
        },
        
        pointTypeCombo, 
    
        
        '-',
        {
            text: "电网类型：", 
            xtype: 'label', 
            style: {
                marginLeft: '20px'
            }
        },
        pointTypeCombo2, 
        '-',
        {
            xtype: 'button',
            text: '搜索',
            iconCls: 'icon-search',
            width: 60,
            style: {
                marginLeft: '20px'
            },
            handler: function() {
                store.load({
                    params: {
                        start: 0, 
                        limit: _pageSize
                    }
                });
            }
        },
        '-',
        {
            xtype: 'button',
            text: '导出',
            iconCls: 'icon-search',
            width: 60,
            style: {
                marginLeft: '20px'
            },
            handler: downloadExcel
        },
        ]),
        bbar: new Ext.PagingToolbar({
            pageSize: _pageSize,
            store: store,
            displayInfo: true,
            displayMsg: '显示记录：{0} - {1}   总记录：{2}',
            emptyMsg: "目前没有" + theme + '信息'
        })
    });
    store.load({
        params: {
            start: 0, 
            limit: _pageSize
        }
    });
    
    var applicationUI = new Ext.Viewport({
        layout: "fit",
        items: [
        grid
        ]
    });
}
Ext.onReady(buildWindow);  